package cate.game.role.show.msg;

import cate.common.util.GameResult;
import cate.game.GameBody;
import cate.game.client.ClientContext;
import cate.game.client.msg.ClientMsg;
import cate.game.client.msg.MsgConfig;
import cate.game.client.msg.MsgInput;
import cate.game.client.msg.id.MsgIdBBlog;
import cate.game.role.Role;
import easy.java.dev.note.NoteField;

@ClientMsg(title = "英雄穿皮肤 の 请求")
public class HeroSkinOnReq implements MsgInput {

	@NoteField("英雄原型id")
	public int heroProtoId;

	@NoteField("皮肤id")
	public int tid;

	@Override
	public void execute(GameBody game, ClientContext cc) {
		GameResult<Void> r =  settle(cc.getRole());
		if (!r.ok()) {
			game.notice.message(cc.getRole(), r, true);
		}
	}

	private GameResult<Void> settle(Role role) {
		GameResult<Void> r = new GameResult<>();
		if (tid > 0) {
			boolean active = role.getShow().heroSkin.isActive(tid);
			if (!active) {
				return r.fail("皮肤未激活");
			}
		}
		role.getShow().heroSkin.illustrate.onSkin(heroProtoId, tid);
		role.sendNow(new HeroSkinOnResp(heroProtoId, tid));
		return r.success();
	}

	@Override
	public MsgConfig conf() {
		return MsgIdBBlog.HERO_SKIN_ON_REQ;
	}
}
